#include <Def.h>
#include <qfile.h>
#include <qtextstream.h>
#include "Celestia.h"

QList<PositionLabel> loadCelestiaSscFile(const QString& filename)
{
	QList<PositionLabel> output;
	QFile file(filename);
	if(!file.open(QIODevice::ReadOnly))
		return output;

	QTextStream stream(&file);

	QString value1,value2;
	PositionLabel label;
	while(!stream.atEnd())
	{
		stream>>value1;
		if(value1.startsWith('#')||value1.isEmpty())
			continue;

		if(value1=="Location")
		{
			stream.skipWhiteSpace();
			stream>>value1;
			if(!value1.endsWith('"'))
			{
				stream>>value2;
				value1.append(' ');
				value1 += value2;
			}
			label.name = value1.remove('"');
		}
		else if(value1=="LongLat")
		{
			double lon,lat,alt;
			stream>>value1;
			stream>>lon;
			stream>>lat;
			stream>>alt;
			stream>>value2;
			label.lon = lon;
			label.lat = lat;
			label.alt = alt;
		}
		else if(value1=="Importance")
		{
			stream>>label.important;
		}
		else if(value1=="}")
			output<<label;
	}
	return output;
}
